package com.boot.unity.api.modules.train.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.*;

import com.boot.unity.api.modules.train.entity.Student;

@Mapper
public interface StudentDao {

    @Update("update train_student set result = #{result} where id = #{id}")
    int updateResult(@Param("id") String id,@Param("result") String result);

    @Update("update train_student set ispost = '1' where id = #{id}")
    int updateIsPost(@Param("id") int id);

    @Select("select * from train_student t where t.id = #{id}")
    Student getById(@Param("id") String id);

//    @Select("select * from train_student t where t.id = #{studentId}")
//    Student getByStudentId(@Param("studentId") String studentId);

    @Delete("delete from train_student where id = #{id}")
    int delete(Long id);

    int update(Student student);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into train_student(school_id, student_id, name, nation, gender, card_type, card_no, nationality, mobile, address, signup_date, learning_categories, train_type, photo_path, photo_url, step, create_time, update_time) values(#{schoolId}, #{studentId}, #{name}, #{nation}, #{gender}, #{cardType}, #{cardNo}, #{nationality}, #{mobile}, #{address}, #{signupDate}, #{learningCategories}, #{trainType}, #{photoPath}, #{photoUrl}, #{step}, now(), now())")
    int save(Student student);

    int count(@Param("params") Map<String, Object> params);

    List<Student> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);

    Student getByStudentId(@Param("studentId") String studentId);

    int saveBase(Student student);

    int savePhoto(Student student);

    int saveStep(Student student);

    int updateBase(Student student);

    int updatePhoto(Student student);

    int updateStep(Student student);

    Student getByCarYes(@Param("cardNo") String cardNo);
    Student getByCarNo(@Param("cardNo") String cardNo);
    Student getByCarNoStopJs(@Param("cardNo") String cardNo);

    @Update("update train_student set status = #{status} where id = #{id}")
    int updateStatusById(@Param("id") Long id, @Param("status") Integer status);

    @Update("update train_student set `status` = '2',ispost = '2' where `status` = '0' and card_no = #{cardNo}")
    int updateStatusByCardNo(@Param("cardNo") String cardNo);

    @Update("update train_student set status = #{status} where student_id = #{studentid}")
    int updateStatusByStudentId(@Param("studentid") String studentid, @Param("status") Integer status);
    /**
     * 学员报名状态 step 字段取值
     * 0:已保存；
     * 1:制证照审核不通过；
     * 2:已上传；
     * 3:上传成功；
     * 4:退办（内⽹审核不通过）；
     * 5:办结（内⽹审核通过）；
     * 6:已领证（学员在六合⼀已归档）；
     * 7:退学（学员在六合⼀退学） 状态为4，退办时，同时有reason字段描述退办原因。
     * @return
     */

    /**
     * DISTINCT 用户处理一个学员填写多次报名信息，进行推送多次无纸化的问题，只是查询一次无纸化的问题
     */
    // and a.school_id != '3331'
//    @Select("select DISTINCT t.card_no,create_time from train_student t,train_stu a where a.card_no = t.card_no and t.train_type = a.train_type and a.tfstatus not like '%1%' and a.step = 'F' AND t.step = 5 and t.status = 0")
    @Select("select DISTINCT t.card_no from train_student t,train_stu a where t.student_id = a.student_id and a.tfstatus not like '%1%' and a.step = 'F' AND t.step = 5 and t.status = 0 LIMIT 0,10")
    List<String> listCardNo4Sync();



    @Select("select t.card_no from train_student t where card_no = '371102198211295099'")
    List<String> list4Test();
}
